#include "pch.h"
#include <iostream>
#include <string>

using namespace std;

class date
{
private:
	int year;
	int month;
	int day;
public:
	date() { }
	date(int y, int m, int d) :year(y), month(m), day(d) { }
	void dateprint() { cout << "创建日期为:" << year << "/" << month << "/" << day << "/" << endl; }
	int getyear() { return year; }
};

class Account
{
protected:
	int AccountNumber;
	float balance;
	float AnnualInterestRate;
	date DateCreated;
public:
	string toString() const { return "账号:" + to_string(AccountNumber) + " 余额:" + to_string(balance); }
	Account(int AccountNumber, float balance, float AnnualInterestRate, int y, int m, int d) :AccountNumber(AccountNumber), balance(balance), AnnualInterestRate(AnnualInterestRate)
	{
		date temp(y, m, d);
		DateCreated = temp;
	}
	void deposit(int deposit) { balance = balance + deposit; }
	void draw(int draw) { balance = balance - draw; }
	void interest(int time)
	{
		for (int i = 0;i < time;i++)
			balance = balance + balance * AnnualInterestRate;
	}
	int getyear() { return DateCreated.getyear(); }
};
class SavingAccounts : public Account
{
public:
	SavingAccounts(int AccountNumber, float balance, float AnnualInterestRate, int y, int m, int d) :Account(AccountNumber, balance, AnnualInterestRate, y, m, d) { }
	void draw(int draw)
	{
		float temp = balance - draw;
		if (temp < 0)
		{
			cout << "操作失败！" << endl;
		}
		else
			balance = temp;
	}
};

class CheckingAccounts : public Account
{
private:
	float OverdraftLimit;
public:
	CheckingAccounts(int AccountNumber, float balance, float AnnualInterestRate, int y, int m, int d, int OverdraftLimit) :Account(AccountNumber, balance, AnnualInterestRate, y, m, d), OverdraftLimit(OverdraftLimit) { }
	void draw(int draw)
	{
		float temp = balance + OverdraftLimit - draw;
		if (temp < 0)
		{
			cout << "操作失败！" << endl;
		}
		else
		{
			balance = temp - OverdraftLimit;
		}
	}
	string toString() const
	{
		string result = "账号:" + to_string(AccountNumber) + " 余额:" + to_string(balance) + " 剩余可透支额度:";
		if (balance >= 0)
			result = result + to_string(OverdraftLimit);
		else
			result = result + to_string(OverdraftLimit + balance);
		return result;
	}
};

int main()
{
	SavingAccounts test1(1, 10000, 0.03, 2010, 8, 7);
	CheckingAccounts test2(2, 0, 0.01, 2012, 3, 4, 20000);
	cout << "请输入当前年份！" << endl;
	int now;
	cin >> now;
	cout << "储存账户存入10000元到现在的余额" << endl;
	int temp = now - test1.getyear();
	test1.interest(temp);
	cout << test1.toString() << endl;
	test2.draw(5000);
	cout << "支票账户透支5000元后" << endl;
	cout << test2.toString() << endl;
}